package factory;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @Author: 金宇峰
 * @Description:   传统的  不是工厂方法
 * @DateTime: 2024/4/2 14:19
 **/
public class tradition {
    public static void main(String[] args) {
        OrderlyPizza orderlyPizza = new OrderlyPizza();

    }
}

abstract class Pizza {
    protected String name;

    public void setName(String name) {
        this.name = name;
    }

    public abstract void prepare();

    public void bake() {
        System.out.println(name + " baking...");
    }

    public void cut() {
        System.out.println(name + " cutting...");
    }

    public void box() {
        System.out.println(name + " boxing...");
    }
}

class GreekPizza extends Pizza {
    @Override
    public void prepare() {
        setName("GreekPizza");
        System.out.println(name + " preparing...");
    }
}

class CheesePizza extends Pizza {
    @Override
    public void prepare() {
        setName("CheesePizza");
        System.out.println(name + " preparing...");
    }
}

class OrderlyPizza {

    public OrderlyPizza() {
        Pizza pizza  ;
        String type = getType();
        do {
            if ("GreekPizza".equals(type)) {
                pizza = new GreekPizza();
            } else if ("greek".equals(type)) {
                pizza = new GreekPizza();
            } else {
                System.out.println("输入类型错误，程序退出");
                break;
            }
            pizza.prepare();
            pizza.bake();
            pizza.cut();
            pizza.box();
        } while (true);
    }

    public String getType() {
        InputStreamReader in = new InputStreamReader(System.in);
        BufferedReader s = new BufferedReader(in);
        try {
            return s.readLine();
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }
}